<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>GT pro钱包</title>
		<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
		<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
		<link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
		<link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
		<link rel="stylesheet" href="bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css">
		<link rel="stylesheet" href="dist/css/AdminLTE.min.css">
		<link rel="stylesheet" href="dist/css/skins/skin-blue.min.css">
		<link rel="stylesheet" href="css/style.css">
		<link rel="stylesheet" href="css/card.css">
		<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
		<link rel="stylesheet" href="bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
	</head>
	<body class="hold-transition skin-blue sidebar-mini">
		<div class="wrapper">
			<div class="content-wrapper">
				<section class="content-header">
					<ol class="breadcrumb">
						<li>
							<a href="#"><i class="fa fa-dashboard"></i>账户管理</a>
						</li>
						<li class="active">管理员管理</li>
					</ol>
				</section>
				<section class="content">
					<div class="box">
						<div class="box-header with-border">
							管理员列表
						</div>
						<div class="box-body">
							<div class="buyu_search_group">
								<div class="row">
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<div class="input-group margin">
											<div class="input-group-btn">
												<button type="button" class="btn btn-default" aria-expanded="false">账户 </button>
											</div>
											<input type="text" class="form-control" id="account">
										</div>
									</div>
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<div class="input-group margin">
											<div class="input-group-btn">
												<button type="button" class="btn btn-default" aria-expanded="false">手机号 </button>
											</div>
											<input type="text" class="form-control" id="mobile">
										</div>
									</div>
									
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<button type="button" class="btn bg-primary margin" onclick="search()"><i class="fa fa-search" ></i>&nbsp;搜索</button>
										<button type="button" class="btn bg-primary margin" onclick="reset()"><i class="fa fa-trash" ></i>&nbsp;重置</button>
									</div>
									<div class="col-xs-12">
										<button type="button" class="btn bg-primary margin" onclick="addAdmin()"><i class="fa fa-plus" ></i>&nbsp;添加</button>
										
									</div>
								</div>
							</div>
						</div>
						<div class="row">
							<div class="col-xs-12">
								<!-- /.box-header -->
								<div class="box-body">
									<table id="example" class="display nowrap table table-bordered table-striped" style="width:100%;">
										<thead>
											<tr>
												<th>ID</th>
												<th>账号</th>
												<th>手机号码</th>
												<th>权限组名称</th>
												<th>添加时间</th>
												<th>备注</th>
												<th>状态</th>
												<th>操作</th>
											</tr>
										</thead>
										<tbody></tbody>
									</table>
								</div>
							</div>
						</div>
					</div>
				</section>
			</div>
		</div>
		<script src="bower_components/jquery/dist/jquery.min.js"></script>
		<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
		<script src="bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
		<script src="bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
		
		<script src="bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
		
		<script src="dist/js/adminlte.min.js"></script>
		<script src="js/argument.js"></script>
		<script src="js/fun.js"></script>
		<script src="js/nav.js"></script>
		<script src="js/pop.js"></script>
		<script src="js/getList.js"></script>
		<!--<script src="js/hsjManagement_fun.js"></script>-->
		
		<script type="text/javascript">
			var table = $('#example').DataTable({
				'ordering': false,
				'lengthChange': false,
				'searching': false,
				'info': true,
				"processing": true,
				"serverSide": true,
				'scrollX':true,
				"ajax": {
					"type": 'post',
					"url": url + "Back_ManagerList",
					'contentType': "application/x-www-form-urlencoded",
					"headers": {
						"auth-token": localStorage.getItem("wallet_token")
					},
					"data": function(d) {
						var data = {};
						data.data=JSON.stringify({
							page_num: d.start / 10 + 1,
							role_id:$('#role_id').val(),
							search_str:$("#search_str").val()
						});
						return data;
					},
					"dataFilter": function(data) {
						var datajson = eval('(' + data + ')');
						if(datajson.status == 1000||datajson.status == 102) {
							ToLogin(datajson)
							return false;
						} else if(datajson.status != 1) {
							alert(datajson.error);
							return false;
						}
						var json = {};
						if(datajson.data==null){
							json.recordsTotal = 0;
							json.recordsFiltered = 0;
							json.data = [];
							return JSON.stringify(json);
						}else{
							json.recordsTotal = datajson.data.total;
							json.recordsFiltered = datajson.data.total;
							json.data = datajson.data.data_list;
							return JSON.stringify(json);
						}
					}
				},
				"columns": [{
						data: 'id'
					},
					{
						data: 'account'
					},
					{
						data: 'mobile'
					},
					
					{
						data: 'role_name'
					},
					{
						data: 'add_time'
					},
					{
						data: 'intro'
					},
					{
						data: null,render:function(data){
							return adminState(data.status)
						}
					},
					{
						data: null,render:function(data){
							var str = "";
							if(data.status==1){
								str="<button type='button' class='btn btn-primary button-margin' onclick='freezeManager(this)'><i class='fa fa-user-times'></i>&nbsp;冻结</button>";
							}else if(data.status==2){
								str="<button type='button' class='btn btn-primary button-margin' onclick='unfreezeManager(this)'><i class='fa  fa-user'></i>&nbsp;解冻</button>";
							}
						return "<input type='hidden' value='" + JSON.stringify(data) + "'><button type='button' class='btn btn-primary button-margin' onclick='editManager(this)' ><i class='fa fa-pencil'></i>&nbsp;修改</button><button type='button' class='btn btn-danger button-margin' onclick='delManager(this)'><i class='fa fa-trash-o'></i>&nbsp;删除</button>"+str;	
					}}
				]
			})
		</script>
		<script type="text/javascript">
			var roleList = getList("Back_RoleList","role_name","id",{is_all:1});
			
			function addSave(){
				$.ajax({
					type: 'post',
					url: url + "Back_ManagerAdd",
					"headers": {
						"auth-token": localStorage.getItem("wallet_token")
					},
					"contentType": "application/x-www-form-urlencoded",
					data: {
						data:JSON.stringify({
							password: $("#addManagerModal [name=password]").val(),
							account: $("#addManagerModal [name=account]").val(),
							mobile: $("#addManagerModal [name=mobile]").val(),
							role_id:$("#addManagerModal [name=roleId]").val(),
						})
					},
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.error);
							return false;
						}
						$("#addManagerModal").modal("hide");
						alert(res.error);
						table.draw(false);
					}
				})
			}
			function addAdmin(){
				var addJson = {
					name: "addManager",
					title: "添加管理员",
					arg: {
						"account": {
							name: "账号",
							type: "text"
						},
						"password": {
							name: "密码",
							type: "text"
						},
						"mobile": {
							name: "手机号",
							type: "text",
						},
						"roleId": {
							name: "角色",
							type: "select",
							list:roleList
						}
					}, //参数
				};
				addModal(addJson, 'addSave');
			}
			
			function editManager(_this){
				var data = JSON.parse($(_this).siblings('input').val())
				var editJson = {
					name: "editManager",
					title: "编辑管理员",
					arg: {
						id: {
							type: "id",
							value:data.id
						},
						mobile: {
							name: "手机号",
							type: "text",
							value:data.mobile
						},
						account: {
							name: "昵称",
							type: "text",
							value:data.account
						},
						password: {
							name: "密码",
							type: "text",
							value:''
						},
						role_id: {
							name: "角色",
							type: "select",
							value:data.role_id,
							list:roleList
						},
						intro: {
							name: "备注",
							type: "textarea",
							value:data.intro
						},
					}, //参数
				};
				editModal(editJson, 'editSave');
			}
			
			function editSave(){
				var data ={
						account:$("#editManagerModal [name=account]").val(),
						mobile:$("#editManagerModal [name=mobile]").val(),
						role_id:$("#editManagerModal [name=role_id]").val(),
						intro:$("#editManagerModal [name=intro]").val(),
						id:$("#editManagerModal [name=id]").val(),
						status:1,
					}
				
				if($("#editManagerModal [name=password]").val()!=''){
					data.password=$("#editManagerModal [name=password]").val();
				}
				$.ajax({
					type:"post",
					"headers": {
						"auth-token": localStorage.getItem("wallet_token")
					},
					"contentType": "application/x-www-form-urlencoded",
					url:url+"Back_ManagerUpdate",
					data:{
						data:JSON.stringify(data),
					},
					dataType:'json',
					success:function(res){
						if(res.status==1){
							alert(res.error)
							$("#editManagerModal").modal("hide");
							table.draw(false);
						}else if(res.status==500){
							window.location.href="login.html";
						}else{
							alert( res.error);
							return false;
						}
					}
				})
			}
		
			function delSave(){
				$.ajax({
					type: "post",
					headers: {
						"auth-token": localStorage.getItem("wallet_token")
					},
					contentType: "application/x-www-form-urlencoded",
					url: url + "Back_ManagerUpdate",
					data:{
						data:JSON.stringify({ 
							id:$('#delManagerModal [name=id]').val(),
							status: 3
						})
					},
					dataType: "json",
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							Tologin(res);
							return false;
						} else if(res.status != 1) {
							alert(res.error);
							return false;
						}
						$("#delManagerModal").modal("hide");
						alert(res.error);
						table.draw(false);
					}
				})
			}
			
			function delManager(_this){
				var data = JSON.parse($(_this).siblings('input').val())
				var deleteJson = {
					name: "delManager",
					title: "删除管理员",
					arg: {
						id: data.id,
						name: data.account
					}
				};
				deleteModal(deleteJson, 'delSave');
			}
			
			function freezeSave(){
				console.log($('#freezeManagerModal [name=id]').val());
				$.ajax({
					type: "post",
					headers: {
						"auth-token": localStorage.getItem("wallet_token")
					},
					contentType: "application/x-www-form-urlencoded",
					url: url + "Back_ManagerUpdate",
					data:{
						data:JSON.stringify({ 
							id:$('#freezeManagerModal [name=id]').val(),
							status: 2
						})
					},
					dataType: "json",
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							Tologin(res);
							return false;
						} else if(res.status != 1) {
							alert(res.error);
							return false;
						}
						$("#freezeManagerModal").modal("hide");
						alert(res.error);
						table.draw(false);
					}
				})
			}
			function freezeManager(_this){
				var data = JSON.parse($(_this).siblings('input').val());
				Json = {
					name: "freezeManager",
					title: "冻结管理员",
					arg: {
						id: data.id,
						name: data.account
					}
				};
				deleteModal(Json, 'freezeSave');
			}
			
			
			function unfreezeSave(){
				
				$.ajax({
					type: "post",
					"headers": {
						"auth-token": localStorage.getItem("wallet_token")
					},
					"contentType": "application/x-www-form-urlencoded",
					url: url + "Back_ManagerUpdate",
					data:{
						data:JSON.stringify({ 
							id:$('#unfreezeManagerModal [name=id]').val(),
							status: 1
						})
					},
					dataType: "json",
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							Tologin(res);
							return false;
						} else if(res.status != 1) {
							alert(res.error);
							return false;
						}
						$("#unfreezeManagerModal").modal("hide");
						alert(res.error);
						table.draw(false);
					}
				})
			}
			function unfreezeManager(_this){
				var data = JSON.parse($(_this).siblings('input').val());
				Json = {
					name: "unfreezeManager",
					title: "解冻管理员",
					arg: {
						id: data.id,
						name: data.account
					}
				};
				deleteModal(Json, 'unfreezeSave');
			}
		</script>
	</body>
</html>